//
//  SHGTabBar.swift
//  -微博准备
//
//  Created by 孙护国 on 16/4/7.
//  Copyright © 2016年 孙护国. All rights reserved.
//

import UIKit

class SHGTabBar: UITabBar {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(plusbtn)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   override func layoutSubviews() {
        super.layoutSubviews()

    let subviewWidth=self.frame.width/5
    let subviewHeight=self.frame.height
    var index:CGFloat=0
    for subview in subviews {
        if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
        subview.frame=CGRectOffset(CGRectMake(0, 0, subviewWidth, subviewHeight), subviewWidth * index, 0)
        index += (index==1) ? 2 : 1
        }
        plusbtn.frame=CGRectOffset(CGRectMake(0, 0, subviewWidth, subviewHeight), subviewWidth*2, 0)
    }
    }
    lazy var plusbtn:UIButton = {
        let btn=UIButton()
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState:.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        return btn
    }()
}
